<?php

namespace App\Http\Controllers;

use App\Notifications\RegistMailNotify;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
{
    public function show(){
        //加载模板
        return view('user.show');
    }

    /**
     * @param $token 激活用户的邮箱用到的token值
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function jihuo($token){
        //通过token值找到用户数据，将账号状态改为1
        $user = User::where('email_token',$token)->first();
        //如果存在，就进行处理
        if($user){
            $user->status = 1;
            $user->save();
            //设置闪存并跳转
            session()->flash('success','账号激活成功！');
            return redirect('/');
        }
    }

    public function sendMail(){
        //获取当前登录的用户数据
//        dd(123);
        $user = auth()->user();
        \Notification::send($user,new RegistMailNotify($user));

        //设置闪存并跳转
        session()->flash('success','邮件已重新发送，请查收！');
        return back();
    }
}
